﻿from pycad.system import *
from pycad.runtime import *

@command()
def testcirjig():
    jig = cirjig()
    res = ed.Drag(jig)
    if res.Status == aced.PromptStatus.OK:
        jig.it = 1
        res = ed.Drag(jig)
        if res.Status == aced.PromptStatus.OK:
            with dbtrans() as tr:
                btr = tr.opencurrspace()
                tr.addentity(btr, jig.Entity)

class cirjig(aced.EntityJig):
    def __new__(cls):
        return aced.EntityJig.__new__(cls, acdb.Circle(acge.Point3d.Origin, acge.Vector3d.ZAxis, 10))
    def __init__(self):
        self.it = 0
        self.center, self.radius = self.Entity.Center, self.Entity.Radius
    def Sampler(self, prompts):
        if self.it == 0:
            opts = aced.JigPromptPointOptions('\n请输入圆心:')
            opts.UserInputControls = \
                aced.UserInputControls.Accept3dCoordinates | \
                aced.UserInputControls.NoZeroResponseAccepted | \
                aced.UserInputControls.NoNegativeResponseAccepted | \
                aced.UserInputControls.NullResponseAccepted
            res = prompts.AcquirePoint(opts)
            if res.Status == aced.PromptStatus.OK:
                if self.center == res.Value:
                    return aced.SamplerStatus.NoChange
                else:
                    self.center = res.Value
                    return aced.SamplerStatus.OK
            return aced.SamplerStatus.Cancel
        elif self.it == 1:
            opts = aced.JigPromptDistanceOptions('\n请输入半径:')
            opts.UserInputControls = \
                aced.UserInputControls.Accept3dCoordinates | \
                aced.UserInputControls.NoZeroResponseAccepted | \
                aced.UserInputControls.NoNegativeResponseAccepted | \
                aced.UserInputControls.NullResponseAccepted
            opts.UseBasePoint = True
            opts.BasePoint = self.center
            opts.Cursor = aced.CursorType.RubberBand
            res = prompts.AcquireDistance(opts)
            if res.Status == aced.PromptStatus.OK:
                if self.radius == res.Value:
                    return aced.SamplerStatus.NoChange
                else:
                    self.radius = res.Value
                    return aced.SamplerStatus.OK
            return aced.SamplerStatus.Cancel
        else:
            return aced.SamplerStatus.Cancel
    def Update(self):
        self.Entity.Center, self.Entity.Radius = self.center, self.radius